{% extends 'base_with_top_menu.html' %}

{% block title %}Location's details{% endblock %}

{% block header %}Location's details{% endblock %}

{% block content %}
    {% if perms.baseapp.list_locations %}
    <div class="inner_menu">
      <ul>
        <li><a href="../">Show all locations</a></li>
        {% if perms.baseapp.add_location %}<li><a href="{% url location_add %}">Add location</a></li>{% endif %}
      </ul>
    </div>
    {% endif %}

    {% if not is_adding %}
    <div class="location_info">
      <ul class="details">
        <li><span class="label">Full name:</span> {{loc.building}}: {{loc.details}}</li>
        <li><span class="label">Building:</span>
          {% if perms.baseapp.view_building %}
            <a href="{% url building_one loc.building.id %}">{{loc.building}}</a>
          {% else %}
            {{loc.building}}
          {% endif %}
        </li>
        <li><span class="label">Maintainers:</span>
          <ul class="maintainers">
            {% for mt in loc.get_all_maintainers %}
            <li>
              {% if perms.baseapp.view_others_profile %}
                <a href="{% url user_one mt.id %}">{{ mt }}</a>
              {% else %}
                {{ mt }}
              {% endif %}
              <ul class="phones">
                <li class="phone">
                    <a class="email" href="mailto:{{ mt.email }}">E-mail: {{ mt.email }}</a>
                </li>
                {% for p in mt.userprofile.phone.all %}
                <li class="phone">
                  {%ifequal p.type.name "Skype" %}   <a class="skype" href="skype:{{p.value}}">{{p.type.name}}: {{p.value}}</a>
                  {% else %}                         {{p.type.name}}: {{p.value}}
                  {% endifequal %}
                </li>
                {% endfor %}
              </ul>
            </li>
            {% empty %}
            Remove all maintainers.
            {% endfor %}
          </ul>
        </li>
        <li><span class="label">Remarks:</span> {{loc.remarks}}</li>
      </ul>
    </div>
    {% endif %}

    <!-- EDIT LOCATION -->
    {% if perms.baseapp.change_location %}
    <div class="form_locationWrapper">
        {% if is_updating %}
          <h2 id="edit_location">Edit location</h2>
        {% else %}
          <h2 id="add_location">Add location</h2>
        {% endif %}

        {% if display_tips %}
        <div class="tip">
          <p>To remove all maintainers from this location, put tick on "No maintainers".</p>
        </div>
        {% endif %}

        <form method="POST" action="." name="Flocation">
            {{ form.non_field_errors }}
            <table>
                {% for field in form %}
                    <tr>
                        <td>{{ field.label_tag }}: <br /> {{ field }}

                          {%if field.label == 'Maintainer'%}
                              <br>
                              <input type="checkbox" id="no_maintainers" name="no_maintainers" />
                              <label for="no_maintainers" title="No maintainers">No maintainers</label>
                          {%endif%}
                        </td>
                        <td>
                          {{ field.errors }}
                        </td>
                    </tr>
                {% endfor %}
                <tr>
                    <td></td>
                    {% if is_updating %}<td><input type="submit" name="btn_update" value="Update location"></td> {% endif %}
                    {% if is_adding %}<td><input type="submit" name="btn_add" value="Add location"></td> {% endif %}
                </tr>
            </table>
        </form>
        <script type="text/javascript">
            document.Flocation.building.focus();
        </script>
    </div>
    {% endif %}

{% endblock %}
